package com.lovo.ssc.controller;


import com.lovo.dto.CommodityDto;
import com.lovo.ssc.bean.Commodity;
import com.lovo.ssc.service.ICommodityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 0-已上架、1-促销中、2-预售商品 商品控制器
 * </p>
 *
 * @author lovo
 * @since 2022-07-11
 */
@RestController
@RequestMapping("/commodity")
@Api(tags = "商品应用控制器--------刘文龙")
@Slf4j
public class CommodityController {
	@Autowired
	ICommodityService commodityService;

	/**
	 * 从商城后台拉取已上架商品
	 * @param commodityDtoList 已上架商品dto集合
	 */
	@PostMapping("findAllCommodityBySscSys")
	public void findAllCommodityBySscSys(List<CommodityDto> commodityDtoList){
		//清空本地已上架商品数据库
		commodityService.trunCateCommodity();
		for (CommodityDto c: commodityDtoList) {
			//数据拷贝
			Commodity commodity = new Commodity();
			commodity.setCommoditycode(c.getCommoditycode());
			commodity.setCommodityname(c.getCommodityname());
			commodity.setCommoditybatch(c.getCommoditybatch());
			commodity.setNorms(c.getNorms());
			commodity.setType(c.getType());
			commodity.setNumber(c.getNumber());
			commodity.setPrice(c.getPrice());
			commodity.setState(c.getState());
			//保存到本地数据库
			commodityService.save(commodity);
		}
	}


	/**
	 * 定时调度，从本地查询出已上架商品，并放入rides
	 */
	@Scheduled(cron = "1 0/1 * * * ? ")
	public void scheduledSaveInRides(){

	}
}
